from utils.dict_utils import get_dict_int_value


class Usage:
    def __init__(self, usage_dict=None):
        self.completion_tokens=0
        self.prompt_tokens=0
        self.total_tokens=0
        #明细（通常为空）
        self.completion_tokens_details=0
        #明细（通常为空）
        self.prompt_tokens_details=0
        self.addTokens(usage_dict)

    def addTokens(self,usage_dict):
        if usage_dict is None:
            return
        self.completion_tokens+=usage_dict.get("completion_tokens",0)
        self.prompt_tokens+=usage_dict.get("prompt_tokens",0)
        self.total_tokens+=usage_dict.get("total_tokens",0)
        print(f'completion_tokens_details={usage_dict["completion_tokens_details"]}')
        print(f'prompt_tokens_details={usage_dict["prompt_tokens_details"]}')
        self.completion_tokens_details+=get_dict_int_value(usage_dict,"completion_tokens_details",0)
        self.prompt_tokens_details+=get_dict_int_value(usage_dict,"prompt_tokens_details",0)
